﻿using SiMay.Sockets.Delegate;
using SiMay.Sockets.Tcp.Client;
using SiMay.Sockets.Tcp.Server;
using SiMay.Sockets.Tcp.Session;
using SiMay.Sockets.Tcp.TcpConfiguration;

namespace SiMay.Sockets.Tcp
{
    public class TcpSocketsFactory
    {
        /// <summary>
        /// 创建SiMay.Socket客户端对象
        /// </summary>
        /// <param name="saeaSessionType">连接模式,Full模式:仅接收发送数据（高性能的数据接收模型,可启用TcpKeepAlive选项）注：数据压缩,AppKeepAlive选项在Full模式下启用无效,Pack模式:自动处理分包（高性能的数据接收模型,自动处理分包,可启用数据压缩,应用层心跳包,TcpKeepAlive选项）,要与服务端一致</param>
        /// <param name="configuration">配置信息</param>
        /// <param name="completetionNotify">客户端的响应事件</param>
        /// <returns></returns>
        public static TcpSocketSaeaClientAgent CreateClientAgent(
            TcpSocketSaeaSessionType saeaSessionType,
            TcpSocketSaeaClientConfiguration configuration,
            NotifyEventHandler<TcpSocketCompletionNotify, TcpSocketSaeaSession> completetionNotify)
        {
            configuration._intervalWhetherService = false;
            return new TcpSocketSaeaClientAgent(saeaSessionType, configuration, completetionNotify);
        }

        /// <summary>
        /// 创建SiMay.Socket服务端对象
        /// </summary>
        /// <param name="saeaSessionType">连接模式,Full模式:仅接收发送数据（高性能的数据接收模型,可启用TcpKeepAlive选项）注：数据压缩,AppKeepAlive选项在Full模式下启用无效,Pack模式:自动处理分包（高性能的数据接收模型,自动处理分包,可启用数据压缩,应用层心跳包,TcpKeepAlive选项）</param>
        /// <param name="configuration">配置信息</param>
        /// <param name="completetionNotify">服务器的响应事件</param>
        /// <returns></returns>
        public static TcpSocketSaeaServer CreateServerAgent(
            TcpSocketSaeaSessionType saeaSessionType,
            TcpSocketSaeaServerConfiguration configuration,
            NotifyEventHandler<TcpSocketCompletionNotify, TcpSocketSaeaSession> completetionNotify)
        {
            configuration._intervalWhetherService = true;
            return new TcpSocketSaeaServer(saeaSessionType, configuration, completetionNotify);
        }
    }
}
